<?php

namespace app\model;

use app\BaseModel;
use think\model\relation\HasMany;

/**
 * 量表类型
 */
class RatingScaleTypeModel extends BaseModel
{
    protected $name = 'rating_scale_type';

    /**
     * 新增数据验证
     * @return array
     */
    public function addValidate(): array
    {
        return [
            'unit_id|单位ID'  => 'require',
            'name|量表分类名'  => 'require',
            'status|状态'  => 'number|max:1',
            'sort|排序'  => 'number|max:11',
        ];
    }

    /**
     * 更新数据验证
     * @return array
     */
    public function updateValidate(): array
    {
        return [
            'status|状态'  => 'number|max:1',
            'sort|排序'  => 'number|max:11',
        ];
    }

    /**
     * 关联多个量表
     * @return HasMany
     */
    public function RatingScale(): HasMany
    {
        return $this->hasMany('RatingScaleModel', 'type_id')->where('status', 1);
    }

    /**
     * 关联多个量表-普通用户版
     * @return HasMany
     */
    public function IsSelfEvaluation(): HasMany
    {
        return $this->hasMany('RatingScaleModel', 'type_id')->where([
            ['status','=', 1],
            ['is_self_evaluation','=',1]
        ]);
    }
}